﻿using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine ;
using System.Text;
using System.Threading.Tasks;
using ActionSystem.Core;
using ActionSystem.Input;
using ActionSystem.Core.ActiveLogic;

namespace ActionSystem.Camera
{
    /// <summary>
    /// 相机
    /// </summary>
    public class ThirdPersonCameraStateMachine:BaseStateMachine, IActiveLogicAbility,ICameraInfo,IInput, ICameraFollowInfoHolder
    {
        
        private BaseActiveLogicAbility logicAbility;
        public BaseActiveLogicAbility GetActiveLogicAbility()
        {
            return logicAbility;
        }
        public override void ResetMachine()
        {
            base.ResetMachine();
            camera = GetComponent<UnityEngine.Camera>();
            if(camera==null)
            {
                throw new Exception("第三人相机没有设置在Camera上");
            }
            logicAbility = new BaseActiveLogicAbility(this);
        }
       
        #region 视角信息
        private new UnityEngine.Camera camera;
        public UnityEngine.Camera GetCamera()
        {
            return camera;
        }
        Vector3 Forward { get; set; }
        Vector3 Right { get; set; }
        Vector3 Up { get; set; }
        public Vector3 GetMoveFarwrd()
        {
            return Forward;
        }

        public Vector3 GetMoveRight()
        {
            return Right;
        }

        public Vector3 GetMoveUp()
        {
            return Up;
        }

        public void SetMoveFarwrd(Vector3 forward)
        {
            if (forward.magnitude < 0.001f)
                Forward = Vector3.zero;
            else
                Forward = forward.normalized;
        }

        public void SetMoveRight(Vector3 right)
        {
            if (right.magnitude < 0.001f)
                Right = Vector3.zero;
            else
                Right = right.normalized;
        }

        public void SetMoveUp(Vector3 up)
        {
            if (up.magnitude < 0.001f)
                Up = Vector3.zero;
            else
                Up = up.normalized;
        }
        #endregion;
        #region 输入
        InputModule input;
        int stickKey;
        /// <summary>
        /// 视角调整
        /// </summary>
        public int StickKey => stickKey;
        int resetKey;
        /// <summary>
        /// 视角重置
        /// </summary>
        public int ResetKey => resetKey;
        /// <summary>
        /// 设置输入模块
        /// </summary>
        /// <param name="input">输入模块</param>
        /// <param name="stickkey">视角旋转摇杆</param>
        /// <param name="resetkey">视角重置按钮</param>
        public void SetInput(InputModule input,int stickKey,int resetKey)
        {
            this.input = input;
            this.stickKey = stickKey;
            this.resetKey = resetKey;
        }
        public InputModule GetInput()
        {
            return input;
        }
        public void SetInput(InputModule input)
        {
            this.input = input;
        }

        #endregion
        #region ICameraFollowInfoHolder

        private ICameraFollowInfo follow;

        public ICameraFollowInfo GetCameraFollow()
        {
            return follow;
        }
        public void SetCameraFollow(ICameraFollowInfo follow)
        {
            this.follow = follow;
        }
        #endregion
    }
}
